package com.sl.biz.modular.job.controller;


import com.sl.biz.modular.job.controller.request.JobAddRequest;
import com.sl.biz.modular.job.controller.request.JobGetByIdRequest;
import com.sl.biz.modular.job.controller.request.JobUpdateByIdRequest;
import com.sl.biz.modular.job.dao.entity.JobConfigDO;
import com.sl.biz.modular.job.service.JobConfigBizService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/job")
@RequiredArgsConstructor
public class JobController {

    private final JobConfigBizService jobConfigBizService;

    @PostMapping("/list")
    public List<JobConfigDO> list(@RequestBody JobConfigDO jobConfigDO) {
        return jobConfigBizService.list(jobConfigDO);
    }

    @PostMapping("/get_by_id")
    public JobConfigDO getById(@RequestBody JobGetByIdRequest jobGetByIdRequest) {
        return jobConfigBizService.getById(jobGetByIdRequest);
    }

    @PostMapping("/add")
    public String add(@RequestBody JobAddRequest jobAddRequest) {
        return jobConfigBizService.add(jobAddRequest);
    }

    @PostMapping("/update_by_id")
    public Boolean updateById(@RequestBody JobUpdateByIdRequest updateByIdRequest) {
        return jobConfigBizService.updateById(updateByIdRequest);
    }

    @PostMapping("/pause/{id}")
    public Boolean pause(@PathVariable("id") String id) {
        return jobConfigBizService.pause(id);
    }

    @PostMapping("/resume/{id}")
    public Boolean resume(@PathVariable("id") String id) {
        return jobConfigBizService.resume(id);
    }

    @PostMapping("/run/{id}")
    public Boolean run(@PathVariable("id") String id) {
        return jobConfigBizService.run(id);
    }

    @PostMapping("/run_one/{id}")
    public Boolean runOnce(@PathVariable("id") String id) {
        return jobConfigBizService.runOnce(id);
    }

    @PostMapping("/next_fire_time/{id}")
    public Date nextFireTime(@PathVariable("id") String id) {
        return jobConfigBizService.nextFireTime(id);
    }

    @PostMapping("/remove/{id}")
    public Boolean remoteById(@PathVariable("id") String id) {
        return jobConfigBizService.remoteById(id);
    }

}
